#include "coorditem.h"
#include <QFont>
#include <QRectF>

CoordItem::CoordItem(GraphWidget *graphWidget)
    : graph(graphWidget),
      text("(0,0)")
{
    setZValue(-1);
}

QRectF CoordItem::boundingRect() const
{
    qreal adjust = ADJUST;
    return QRectF(0-adjust, 0-adjust,
                  100+adjust, 10+adjust);
}

void CoordItem::setNewCoord(QPointF newCoord)
{
    //TODO
    text = QString("(%1,%2)").arg(newCoord.x())
            .arg(newCoord.y());
#ifdef DEBUG
    qDebug() << text;
#endif
}

void CoordItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    QFont font = painter->font();
    font.setPointSize(FONTSIZE);
    painter->setFont(font);
    painter->setPen(Qt::black);
    painter->drawText(QRectF(0,0, 100, 20), text);
}

QString CoordItem::getText()
{
    return text;
}
